package com.qf.openapi.web.master.controller;

import com.qf.openapi.web.master.vo.ResultVo;
import com.qf.openapi.web.master.exception.UserException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义异常处理器
 */
@RestControllerAdvice
@Slf4j
public class ExHandler {

    /**
     * 处理用户模块异常
     *
     * @return
     */
    @ExceptionHandler(UserException.class)
    public ResultVo handleUserEx(UserException ex) {
        log.debug("用户模块异常，ex={}", ex.getMsg());

        //返回
        return ResultVo.error(ex.getMsg());
    }

    /**
     * 兜底异常处理
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResultVo handleEx(Exception ex) {
        log.debug("用户模块异常，ex={}", ex.getMessage());

        //返回
        return ResultVo.error(ex.getMessage());
    }
}
